home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_096 / animplayer / display.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  287 lines

  1. /**********************************************************
  2.  *
  3.  *   NAME
  4.  *      Display -- display animation frames 
  5.  *
  6.  *   SYNOPSIS
  7.  *      Display();
  8.  *
  9.  *   DESCRIPTION
  10.  *      This function displays the specified HAM animation frames in
  11.  *      order.
  12.  *
  13.  *      copyright (c) 1987 Martin D. Hash
  14.  * 
  15.  *   LAST EDITED
  16.  *      Martin Hash                        22 Aug 1987
  17.  *
  18.  *   EDIT HISTORY
  19.  *      19 Dec 1986  MH  Created.
  20.  *      31 Dec           Added Dongel.
  21.  *      21 Mar 1987     Added real-time playback.
  22.  *     5 Jul         More filename suffixes.
  23.  *    11 Aug         Standard filerequest.
  24.  *    16 Aug         ANIM standard.
  25.  *
  26.  **********************************************************/
  27.  
  28. #include <exec/types.h>
  29. #include <exec/memory.h>
  30. #include <intuition/intuition.h>
  31. #include <graphics/gfxbase.h>
  32. #include <graphics/sprite.h>
  33. #include "df1:FileCons.h"
  34. #include "df1:ANIMCons.h"
  35.  
  36. /* EXTERNAL FUNCTIONS */
  37.  
  38. void Display(),
  39.      LoadIFF(),
  40.      Display_Aud();
  41. struct Window *OpenWindow();
  42. struct ColorMap *GetColorMap();
  43. BOOL Manual(),
  44.      FileRequest();
  45. char *strrchr();
  46. FrameNode *Call_Pack();
  47.  
  48. /* LOCAL CONSTANTS */
  49.  
  50. #define RECORD             1
  51. #define VIEW            2
  52. #define NOT_ENOUGH_MEMORY    -1000
  53. #define WIDTH            352
  54. #define HEIGHT            240
  55.  
  56. /* GLOBAL VARIABLES */
  57.  
  58. struct Window *window;
  59. struct IntuitionBase *IntuitionBase;
  60. struct GfxBase *GfxBase;
  61. struct ViewPort viewport1, viewport2;
  62. struct BitMap bitmap1, bitmap2;
  63. struct View view1, view2;
  64. struct RastPort rastport1, rastport2;
  65. FrameNode *patriarch;
  66. int start;
  67.  
  68. char animpathname[STRINGSIZE],
  69.      numbertext[MAXNUMBERTEXT];
  70. struct IntuiText framenumbertext = {
  71.    1, 0, JAM2,
  72.    0, 0, NULL,
  73.    numbertext,
  74.    NULL
  75. };
  76.  
  77. /* FILE VARIABLES */
  78.  
  79. static UBYTE *displaymem;
  80. static struct View *oldview;
  81. static struct RasInfo rastinfo1, rastinfo2;
  82.  
  83. static BOOL iff = FALSE;
  84.  
  85. static UWORD blank_pointer[] = { 0, 0, 0,0,0,0, 0, 0 };
  86.  
  87. static struct NewWindow newwindow = {
  88.    0, 0, 640, 200,
  89.    0, 1, 
  90.    MOUSEBUTTONS | GADGETUP | GADGETDOWN | REQCLEAR | RAWKEY,
  91.    ACTIVATE | SMART_REFRESH,
  92.    NULL,
  93.    NULL, NULL, NULL, NULL,
  94.    0, 0, 0, 0,
  95.    WBENCHSCREEN
  96. };
  97.  
  98. /* This is the first function of the Audition program, hence it needs
  99.  * to include main(). */
  100.  
  101. main()
  102. {
  103.    /* LOCAL VARIABLES */
  104.  
  105.    UWORD i;
  106.    char *dummy,
  107.         *suffix;
  108.    UWORD depth = 0;
  109.  
  110.    /* FUNCTION */
  111.  
  112.    /* open libraries */   
  113.    if ((IntuitionBase = (struct IntuitionBase *)
  114.     OpenLibrary( "intuition.library", INTUITION_REV )) == NULL)
  115.       exit( 0 );
  116.    if ((GfxBase = (struct GfxBase *)
  117.     OpenLibrary( "graphics.library", GRAPHICS_REV )) == NULL) {
  118.       CloseLibrary( IntuitionBase );
  119.       exit( 0 );
  120.    }
  121.    if ((window = OpenWindow( &newwindow )) == NULL) {
  122.       CloseLibrary( IntuitionBase );
  123.       CloseLibrary( GfxBase );
  124.       exit( 0 );
  125.    }
  126.  
  127.    strcpy( animpathname, "frames:anim/" );
  128.    if (FileRequest( "Load Vignette", "  Load", animpathname, window, NULL )) {
  129.       if (!stcpm( animpathname, ".", &suffix )) {
  130.          CloseLibrary( IntuitionBase );
  131.          CloseLibrary( GfxBase );
  132.      CloseWindow( window );
  133.          exit( 0 );
  134.       }
  135.             
  136.       if (stcpm( suffix, "4096", &dummy )) 
  137.          depth = 6;
  138.       else if (stcpm( suffix, "32", &dummy ))
  139.      depth = 5;
  140.       else if (stcpm( suffix, "4", &dummy ))
  141.         depth = 2;
  142.       else if (stcpm( suffix, "8", &dummy ))
  143.      depth = 3;
  144.       else if (stcpm( suffix, "16", &dummy ))
  145.      depth = 4;
  146.       else if (stcpm( suffix, "2", &dummy ))
  147.      depth = 1;
  148.  
  149.       if (stcpm( suffix, "PAC", &dummy ))
  150.          iff = FALSE;
  151.       else if (stcpm( suffix, "IFF", &dummy )) 
  152.          iff = TRUE;
  153.  
  154.       if (depth == 0) {
  155.          CloseLibrary( IntuitionBase );
  156.          CloseLibrary( GfxBase );
  157.      CloseWindow( window );
  158.          exit( 0 );
  159.       }
  160.  
  161.       oldview = GfxBase->ActiView;
  162.    
  163.       InitView( &view1 );
  164.       InitView( &view2 );
  165.       view1.Modes |= LACE;
  166.       view2.Modes |= LACE;
  167.       InitVPort( &viewport1 );
  168.       InitVPort( &viewport2 );
  169.       view1.ViewPort = &viewport1;
  170.       view2.ViewPort = &viewport2;
  171.  
  172.       InitBitMap( &bitmap1, depth, WIDTH, HEIGHT );
  173.       InitBitMap( &bitmap2, depth, WIDTH, HEIGHT );
  174.  
  175.       rastinfo1.RxOffset = 0;
  176.       rastinfo2.RxOffset = 0;
  177.       rastinfo1.RyOffset = 0;
  178.       rastinfo2.RyOffset = 0;
  179.       rastinfo1.Next = NULL;
  180.       rastinfo2.Next = NULL;
  181.       rastinfo1.BitMap = &bitmap1;
  182.       rastinfo2.BitMap = &bitmap2;
  183.  
  184.       viewport1.DWidth = WIDTH;
  185.       viewport2.DWidth = WIDTH;
  186.       viewport1.DHeight = HEIGHT;
  187.       viewport2.DHeight = HEIGHT;
  188.       viewport1.DxOffset = -16;
  189.       viewport2.DxOffset = -16;
  190.       viewport1.DyOffset = -20;
  191.       viewport2.DyOffset = -20;
  192.       viewport1.RasInfo = &rastinfo1;
  193.       viewport2.RasInfo = &rastinfo2;
  194.       if (depth == 6) {
  195.          viewport1.Modes |= HAM;
  196.          viewport2.Modes |= HAM;
  197.       }
  198.       for (i = 0; i < depth; ++i) {
  199.          bitmap1.Planes[i] = (PLANEPTR)AllocRaster( WIDTH, HEIGHT );
  200.          bitmap2.Planes[i] = (PLANEPTR)AllocRaster( WIDTH, HEIGHT );
  201.       }
  202.  
  203.       viewport1.ColorMap = GetColorMap(COLORS);
  204.       viewport2.ColorMap = GetColorMap(COLORS);
  205.       MakeVPort( &view1, &viewport1 );
  206.       MakeVPort( &view2, &viewport2 );
  207.       MrgCop( &view1 );
  208.       MrgCop( &view2 );
  209.  
  210.       InitRastPort( &rastport1 );
  211.       rastport1.BitMap = &bitmap1;
  212.       InitRastPort( &rastport2 );
  213.       rastport2.BitMap = &bitmap2;
  214.  
  215.       SetAPen( &rastport1, 0 );
  216.       RectFill( &rastport1, 0, 0, WIDTH-1, HEIGHT-1 );
  217.       SetAPen( &rastport2, 0 );
  218.       RectFill( &rastport2, 0, 0, WIDTH-1, HEIGHT-1 );
  219.  
  220.       Display();
  221.  
  222.       FreeColorMap( viewport1.ColorMap );
  223.       FreeColorMap( viewport2.ColorMap );
  224.       FreeVPortCopLists( &viewport1 );
  225.       FreeVPortCopLists( &viewport2 );
  226.       FreeCprList( view1.LOFCprList );
  227.       FreeCprList( view2.LOFCprList );
  228.       FreeCprList( view1.SHFCprList );
  229.       FreeCprList( view2.SHFCprList );
  230.       for (i = 0; i < depth; ++i) {
  231.          FreeRaster( bitmap1.Planes[i], WIDTH, HEIGHT );
  232.          FreeRaster( bitmap2.Planes[i], WIDTH, HEIGHT );
  233.       }
  234.    }
  235.    
  236.    CloseWindow( window );
  237.    CloseLibrary( IntuitionBase );
  238.    CloseLibrary( GfxBase );
  239.    OpenWorkBench();
  240. }
  241.  
  242. /* FUNCTION */
  243.  
  244. void Display()
  245. {
  246.    /* LOCAL VARIABLES */
  247.  
  248.    int frame;
  249.    char *framenumber;
  250.  
  251.    /* CODE */
  252.  
  253.    LoadView( &view1 );
  254.  
  255.    if (iff) {
  256.       strcat( animpathname, "/" );
  257.       while (FileRequest( "Load Frame", "  Load", animpathname,
  258.        window, NULL )) {
  259.          SetPointer( window, &blank_pointer, 2, 8, 0, 0 );
  260.          if (framenumber = strrchr( animpathname, '/' ));
  261.      else
  262.             framenumber = strrchr( animpathname, ':' );
  263.  
  264.          stcd_i( framenumber+1, &start ); 
  265.          *(framenumber+1) = '\0';    /* leave only path */
  266.          for (frame = start; TRUE; ++frame) {
  267.             LoadIFF( frame, &bitmap1, &viewport1 );
  268.             if (Manual( &rastport1, &viewport1 ))
  269.                break;
  270.      }
  271.          LoadView( oldview );  
  272.          ClearPointer( window );
  273.       }
  274.    }
  275.    else {
  276.       SetPointer( window, &blank_pointer, 2, 8, 0, 0 );
  277.       patriarch = Call_Pack( animpathname, &bitmap1, &bitmap2, 
  278.        &viewport1, &viewport2 );
  279.       Display_Aud();
  280.       ClearPointer( window );
  281.       LoadView( oldview );  
  282.    }
  283. }
  284.  
  285.  
  286.  
  287.